#include <stdio.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/types.h>
#include <string.h>

using namespace std;

#include <string>
#include <iostream>
#include <unistd.h>

#define PATH "./"
#define ID 0x6666
#define SIZE 4096
#define MODE 0666



int main()
{
    int shmid = shmget(ftok(PATH,ID), SIZE, IPC_CREAT | IPC_EXCL | MODE);
    char* shmaddr =  (char*)shmat(shmid,NULL,0);
    int n = 0;
    int times = 5;
    while(times--)
    {
        // string msg = "i am process A:";
        // msg += to_string(n);
        // n++;
        char buffer[128] = {0};
        sprintf(buffer, "%s: %d", "i am process A:", n++);
        
        memcpy(shmaddr, buffer, strlen(buffer)+1); 
        sleep(1);
    }

    return 0;
}